import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { resolve } from "path";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  resolve: {
    // 配置路径别名
    alias: {
      "@": resolve(__dirname, "src"),
      // "@": "/src",
      // src: "@/",
    },
    // 配置文件扩展名
    extensions: [".ts", ".vue", ".js", ".jsx", ".tsx"], // 导入时想要省略的扩展名列表。
  },
  // 开发服务器配置
  server: {
    port: 8000,
    open: true,
    // 代理服务器配置
    proxy: {
      // 例 https://nb.meituan.com/ptapi/recommends -> /app-dev/recommends
      // "/app-dev": "http://localhost:5000",
      "/app-dev": {
        target: "http://localhost:5000",
        changeOrigin: true, // 允许跨域
        rewrite: (path) => path.replace(/^\/app-dev/, ""),
      },
    },
  },
  define:{
    'process.env':process.env
  }
});

